import { asyncRoutes, constantRoutes } from '@/router/index'
const state = {
  routes: []
}
const mutations = {
  setRouter(state, newRoutes) {
    // 保存静态和动态路由
    state.routes = [...constantRoutes, ...newRoutes]
  }
}

const actions = {
  // 过滤路由
  filterRoutes(store, menus) {
    const newRoutes = asyncRoutes.filter((item) => {
      return menus.includes(item.name)
    })
    store.commit('setRouter', newRoutes)
    return newRoutes
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
